package com.gxa.xiaoucomeshome.controller;

import com.gxa.xiaoucomeshome.exception.BusinessException;
import com.gxa.xiaoucomeshome.exception.ExceptionCode;
import com.gxa.xiaoucomeshome.pojo.*;
import com.gxa.xiaoucomeshome.service.AdminService;
import com.gxa.xiaoucomeshome.service.LogService;
import com.gxa.xiaoucomeshome.service.UserManagerService;
import com.gxa.xiaoucomeshome.utils.FormatTool;
import com.gxa.xiaoucomeshome.utils.JsonResult;
import com.gxa.xiaoucomeshome.utils.PasswordUtils;
import com.gxa.xiaoucomeshome.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;

@RequestMapping("/admin")
@RestController
@Api(tags = "总站台管理员功能模块(data)")
public class AdminController {
    @Autowired
    AdminService adminService;

    @Autowired
    LogService logService;

    @Autowired
    UserManagerService userManagerService;
    @ApiOperation(value = "管理员登录",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin",value = "总后台管理员手机号,密码",paramType = "body",dataType = "Admin",required = true)

    })
    @PostMapping(value = "/login")
    public Map<String,Object> login(@RequestBody Admin admin, @ApiIgnore HttpSession session) throws Exception {
        Admin admin1 = adminService.login(admin.getAdmin_phone(),admin.getAdmin_pwd());
        //登录成功,返回token值
        String token = UUID.randomUUID().toString().replaceAll("-", "");
        //token存到服务器
        session.setAttribute("token",token);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("登录成功");
        jsonResult.set("token",token);
        jsonResult.setData(admin1);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "首页展示",produces = "query")
    @PostMapping(value = "/firstPage")
    public Map<String,Object> show( @ApiIgnore HttpSession session) throws Exception {
        InfoVo infoVo = adminService.showInfo();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(infoVo);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "用户协议(params)",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "agree_desc",value = "协议内容",paramType = "query",dataType = "String",required = true)
    })
    @PostMapping(value = "/userAgree")
    public Map<String,Object> userAgree(@RequestParam("agree_desc") String agree_desc, @ApiIgnore HttpSession session) throws Exception {
        JsonResult jsonResult = new JsonResult();
        if (agree_desc.equals("")||agree_desc==null){
            jsonResult.setCode("201");
            jsonResult.setMsg("协议内容不能为空");
            return jsonResult.getMap();
        }
        adminService.userAgree(agree_desc);
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "站点分页查询",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "siteVo",value = "站点对象",paramType = "body",dataType = "SiteVo"),
    })
    @PostMapping(value = "/siteQuery")
    public Map<String,Object> siteQuery(@RequestBody SiteVo siteVo, @ApiIgnore HttpSession session) throws Exception {
        if (!(siteVo.getPage()>0 && siteVo.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        List<Site> sites = adminService.selectSites((siteVo.getPage() - 1) * siteVo.getSize(), siteVo.getSize(),siteVo.getSite_name());
        Integer total = adminService.selectSitesCount(siteVo.getSite_name());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(sites);
        jsonResult.set("total",total);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "根据编号查询站点",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "siteVo",value = "站点对象",paramType = "body",dataType = "SiteVo"),
    })
    @PostMapping(value = "/selectSiteById")
    public Map<String,Object> selectSiteById(@RequestBody SiteVo siteVo, @ApiIgnore HttpSession session) throws Exception {
        Site site = adminService.selectSiteById(siteVo.getSite_id());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(site);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "站点批量删除",produces = "query")
    @PostMapping(value = "/siteDelete")
    public Map<String,Object> siteDelete(@RequestBody List<Site> site, @ApiIgnore HttpSession session) throws Exception {
        for (int i=0;i<site.size();i++){
            int j = adminService.deleteSiteById(site.get(i).getSite_id());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "站点单个删除(params)",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "站点编号",paramType = "String")
    })
    @PostMapping(value = "/siteDeleteById")
    public Map<String,Object> siteDeleteById( @ApiIgnore HttpSession session,HttpServletRequest request) throws Exception {
        Integer id = FormatTool.formatInteger(request.getParameter("site_id"));
        int i = adminService.deleteSiteById(id);
        JsonResult jsonResult = new JsonResult();
        if (i>0){
            jsonResult.setCode("200");
            jsonResult.setMsg("删除成功");
            return jsonResult.getMap();
        }else {
            jsonResult.setCode("201");
            jsonResult.setMsg("删除失败");
            return jsonResult.getMap();
        }
    }

    @ApiOperation(value = "添加站点",produces = "query")
    @PostMapping(value = "/addSite")
    public Map<String,Object> addSite(@RequestBody Site site, @ApiIgnore HttpSession session) throws Exception {
        adminService.addSite(site);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "修改站点信息",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "site",value = "站点对象",paramType = "body",dataType = "Site")
    })
    @PostMapping(value = "/editSite")
    public Map<String,Object> editSite(@RequestBody Site site, @ApiIgnore HttpSession session) throws Exception {
        adminService.editSite(site);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }


    @ApiOperation(value = "添加站员",produces = "body")
    @ApiImplicitParams({
            @ApiImplicitParam( name = "manager",value = "站员对象",paramType = "body",dataType = "Manager"),
    })
    @PostMapping(value="/addManager")
    public Map addManager(@RequestBody  Manager manager,@ApiIgnore HttpSession session) throws BusinessException {
        if(manager.getPwd()==null || manager.getPwd().equals("")){
            PasswordUtils passwordUtils = new PasswordUtils();
            manager.setPwd(passwordUtils.passwordUtils("123456"));
        }
        adminService.addManager(manager);
        JsonResult jsonResult =new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        jsonResult.setData(manager);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "编辑站员信息",produces = "body")
    @ApiImplicitParams({
            @ApiImplicitParam( name = "manager",value = "站员对象",paramType = "body",dataType = "Manager"),
    })
    @PostMapping(value="/editManager")
    public Map editManager(@RequestBody Manager manager,@ApiIgnore HttpSession session) throws BusinessException {
        adminService.editManager(manager);
        JsonResult jsonResult =new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        jsonResult.setData(manager);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "站员模糊分页查询",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "managerVo",value = "站员对象",paramType = "body",dataType = "ManagerVo",required = false),
    })
    @PostMapping(value = "/selectManager")
    public Map<String,Object> selectManager(@RequestBody ManagerVo managerVo, @ApiIgnore HttpSession session, HttpServletRequest request) throws Exception {
        if (!(managerVo.getPage()>0 && managerVo.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        List<Manager> managers = adminService.selectManager((managerVo.getPage() - 1) * managerVo.getSize(), managerVo.getSize(),managerVo.getMgr_phone());
        Integer total = adminService.selectManagerCount(managerVo.getMgr_phone());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(managers);
        jsonResult.set("total",total);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "查询所有的地址",produces = "query")
    @PostMapping(value = "/selectAddress")
    public Map<String,Object> selectAddress( @ApiIgnore HttpSession session) throws Exception {
        List<SiteAddress> siteAddress = adminService.selectAddress();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(siteAddress);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "站员批量删除",produces = "query")
    @PostMapping(value = "/managerDelete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "managerVo",value = "站员对象",paramType = "body", dataType = "ManagerVo",required = true),
    })
    public Map<String,Object> managerDelete(@RequestBody List<ManagerVo> managerVo, @ApiIgnore HttpSession session) throws Exception {
        for (int j =0;j<managerVo.size();j++){
            int i = adminService.deleteManagerById(managerVo.get(j).getMgr_id());
            System.out.println(managerVo.get(j).getMgr_id()+"123132");
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "站员单个删除(params)",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mgr_id",value = "站员编号",paramType = "query",required = true),
    })
    @PostMapping(value = "/managerDeleteById")
    public Map<String,Object> managerDeleteById( Integer mgr_id, @ApiIgnore HttpSession session) throws Exception {
        JsonResult jsonResult = new JsonResult();
        int i = adminService.deleteManagerById(mgr_id);
        if (i > 0) {
            jsonResult.setCode("200");
            jsonResult.setMsg("删除成功");
            return jsonResult.getMap();
        }
        else {
            jsonResult.setCode("201");
            jsonResult.setMsg("删除失败");
            return jsonResult.getMap();
        }
    }
    @ApiOperation(value = "根据编号查询站员(params)",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mgr_id",value = "站员编号",paramType = "String",required = true),
    })
    @PostMapping(value = "/selectManagerById")
    public Map<String,Object> selectManagerById( Integer mgr_id, @ApiIgnore HttpSession session) throws Exception {
        ManagerVo manager = adminService.selectManagerById(mgr_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(manager);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "根据电话查询配送员(params)",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "配送员电话",paramType = "String",dataType = "String",required = true),
    })
    @PostMapping(value = "/selectCourierByPhone")
    public Map<String,Object> selectCourierByPhone( String  phone, @ApiIgnore HttpSession session) throws Exception {
        Courier courier = adminService.selectCourierByPhone(phone);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(courier);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "配送员模糊分页查询",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courierVo",value = "配送员对象",paramType = "body",dataType = "CourierVo",required = true),
    })
    @PostMapping(value = "/selectCourier")
    public Map<String,Object> siteCourier(@RequestBody CourierVo courierVo, @ApiIgnore HttpSession session) throws Exception {
        if (!(courierVo.getPage()>0 && courierVo.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        List<Courier> couriers = adminService.selectCourier((courierVo.getPage() - 1) * courierVo.getSize(), courierVo.getSize(),courierVo.getPhone(),courierVo.getState());
        Integer total = adminService.selectCourierCount(courierVo.getPhone(),courierVo.getState());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(couriers);
        jsonResult.set("total",total);
        return jsonResult.getMap();
    }


    @ApiOperation(value = "查询所有交通工具",produces = "query")
    @PostMapping(value = "/selectVehicle")
    public Map<String,Object> selectVehicle( @ApiIgnore HttpSession session) throws Exception {
        List<Courier> couriers = adminService.selectVehicle();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(couriers);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "查询所有门店名",produces = "query")
    @PostMapping(value = "/selectSiteName")
    public Map<String,Object> selectSiteName( @ApiIgnore HttpSession session) throws Exception {
        List<Site> sites = adminService.selectSiteName();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(sites);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "添加配送员",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courier",value = "配送员对象",paramType = "body",dataType = "Courier")
    })
    @PostMapping(value = "/addCourice")
    public Map<String,Object> addCourice(@RequestBody Courier courier,@ApiIgnore HttpSession session) throws Exception {
        if (courier.getPassword()==null && courier.getPassword().equals("")){
            courier.setPassword("123456");
        }
         int i = adminService.addCourice(courier.getPhone(),courier.getPassword(),courier.getConame(),courier.getGender(),courier.getAge(),courier.getVehicle(),courier.getDrivingPermit(),courier.getIdCard(),courier.getDrivingLicense(),courier.getSource());
        JsonResult jsonResult = new JsonResult();
        if (i > 0) {
            jsonResult.setCode("200");
            jsonResult.setMsg("添加成功");
            return jsonResult.getMap();
        }else {
            jsonResult.setCode("201");
            jsonResult.setMsg("添加失败");
            return jsonResult.getMap();
        }
    }

    @ApiOperation(value = "配送员批量删除",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courier",value = "配送员对象数组",paramType = "body",dataType = "Courier",required = true),
    })
    @PostMapping(value = "/courierDelete")
    public Map<String,Object> courierDelete(@RequestBody List<Courier> courier, @ApiIgnore HttpSession session) throws Exception {

        for (int i = 0; i < courier.size(); i++) {
            int j = adminService.courierDeleteByPhone(courier.get(i).getPhone());
            System.out.println(courier.get(i).toString());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "配送员单个删除(params)",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "配送员电话",paramType = "String",required = true),
    })
    @PostMapping(value = "/courierDeleteByPhone")
    public Map<String,Object> courierDeleteByPhone( String  phone, @ApiIgnore HttpSession session) throws Exception {
        int i = adminService.courierDeleteByPhone(phone);
        System.out.println(phone+"phone");
        JsonResult jsonResult = new JsonResult();
        if (i>0){
            jsonResult.setCode("200");
            jsonResult.setMsg("删除成功");
            return jsonResult.getMap();

        }else{
            jsonResult.setCode("201");
            jsonResult.setMsg("删除失败");
            return jsonResult.getMap();
        }
    }

    @ApiOperation(value = "修改配送员信息",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courier",value = "配送员对象",paramType = "body",dataType = "Courier")
    })
    @PostMapping(value = "/editCourice")
    public Map<String,Object> editCourice(@RequestBody Courier courier,@ApiIgnore HttpSession session) throws Exception {
        adminService.editCourier(courier.getPhone(),courier.getPassword(),courier.getConame(),courier.getGender()
                ,courier.getPhone(),courier.getVehicle(),courier.getDrivingPermit(),courier.getIdCard(),
                courier.getDrivingLicense(),courier.getSource(),courier.getPhone());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }


    @ApiOperation(value = "配送员批量冻结",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courier",value = "配送员对象数组",paramType = "body",dataType = "Courier",required = true),
    })
    @PostMapping(value = "/freezeCourier")
    public Map<String,Object> freezeCourier(@RequestBody List<Courier> courier, @ApiIgnore HttpSession session) throws Exception {
        for (int i = 0; i < courier.size(); i++) {
            int j =adminService.freezeCourierByPhone(courier.get(i).getPhone());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("冻结成功");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "修改管理员密码",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminVo",value = "修改密码对象",paramType = "body",dataType = "AdminVo",required = true),
    })
    @PostMapping(value = "/updatePwd")
    public Map<String,Object> updatePwd(@RequestBody AdminVo adminVo, @ApiIgnore HttpSession session) throws Exception {
        String pwd = adminService.selectPwdById(adminVo.getAdminId());
        JsonResult jsonResult = new JsonResult();
        if (adminVo.getAdminId() ==null){
            jsonResult.setCode("203");
            jsonResult.setMsg("管理员编号不能为空");
            return jsonResult.getMap();
        }
        if (!pwd.equals(adminVo.getOldPassword())){
            jsonResult.setCode("201");
            jsonResult.setMsg("旧密码输入错误");
            return jsonResult.getMap();
        }else if (!adminVo.getNewPassword().equals(adminVo.getNewPassword1())){
            jsonResult.setCode("202");
            jsonResult.setMsg("两次密码不一致");
            return jsonResult.getMap();
        }
        int i = adminService.updatePwd(adminVo.getAdminId(),adminVo.getNewPassword());
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "配送员批量解冻",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courier",value = "配送员对象数组",paramType = "body",dataType = "Courier",required = true),
    })
    @PostMapping(value = "/thawCourier")
    public Map<String,Object> thawCourier(@RequestBody List<Courier> courier, @ApiIgnore HttpSession session) throws Exception {
        for (int i = 0; i < courier.size(); i++) {
            int j =adminService.thawCourierByPhone(courier.get(i).getPhone());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("解冻成功");
        return jsonResult.getMap();
    }


    @ApiOperation(value = "商品模糊查询",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsChild",value = "商品名",paramType = "body",dataType = "GoodsChild",required = false),
    })
    @PostMapping(value = "/selectGoodsByName")
    public Map<String,Object> selectGoodsByName(@RequestBody GoodsChild  goodsChild, @ApiIgnore HttpSession session) throws Exception {
        if (!(goodsChild.getPage()>0 && goodsChild.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        Map<String ,Object> map = new HashMap<>();
        List<Commodity> commodities = adminService.selectCommodity();
        Integer total = 0;
        String name = null;
        List<String > list = new ArrayList<>();
        for (int i=0;i<commodities.size();i++){
            int id = commodities.get(i).getId();
            name = commodities.get(i).getCommodity_name();
            list.add(name);
            String goodsId = commodities.get(i).getId().toString();
            total = adminService.selectGoodsChildCount(id,goodsChild.getGoods_child_name());
            List<GoodsChild> goodsChildList = adminService.goodsChildList((goodsChild.getPage() - 1) * goodsChild.getSize(), goodsChild.getSize(),id,goodsChild.getGoods_child_name());
            map.put(goodsId,goodsChildList);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(map);
        jsonResult.set("goodsName",list);
        jsonResult.set("total",total);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "修改父类商品信息",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commodity",value = "父类商品对象",paramType = "body",dataType = "Commodity",required = true),
    })
    @PostMapping(value = "/updateGoods")
    public Map<String,Object> updateGoods(@RequestBody Commodity commodity, @ApiIgnore HttpSession session) throws Exception {
        int i = adminService.updateGoods(commodity.getCommodity_name(),commodity.getId());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "修改子类商品信息",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsChild",value = "子类商品对象",paramType = "body",dataType = "GoodsChild",required = true),
    })
    @PostMapping(value = "/updateGoodsChild")
    public Map<String,Object> updateGoods(@RequestBody GoodsChild goodsChild, @ApiIgnore HttpSession session) throws Exception {
        int i = adminService.updateGoodsChild(goodsChild.getGoods_child_name(),goodsChild.getGoods_child_id(),goodsChild.getGoods_id());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "批量删除子类商品信息",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsChild",value = "子类商品对象数组",paramType = "body",dataType = "GoodsChild",required = true),
    })
    @PostMapping(value = "/deleteGoodsChild")
    public Map<String,Object> deleteGoodsChild(@RequestBody List<GoodsChild> goodsChild, @ApiIgnore HttpSession session) throws Exception {
        for (int i = 0; i < goodsChild.size(); i++) {
            int j = adminService.deleteGoodsChild(goodsChild.get(i).getGoods_child_id());
        }

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "添加父类商品信息",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commodity",value = "父类对象",paramType = "body",dataType = "Commodity",required = true),
    })
    @PostMapping(value = "/addGoods")
    public Map<String,Object> addGoods(@RequestBody Commodity commodity, @ApiIgnore HttpSession session) throws Exception {
        int i = adminService.addGoods(commodity.getCommodity_name());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "添加子类商品信息",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsChild",value = "子类对象",paramType = "body",dataType = "GoodsChild",required = true),
    })
    @PostMapping(value = "/addGoodsChild")
    public Map<String,Object> addGoodsChild(@RequestBody GoodsChild goodsChild, @ApiIgnore HttpSession session) throws Exception {
        int i = adminService.addGoodsChild(goodsChild.getGoods_child_name(),goodsChild.getGoods_id());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "查询Log日志",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "log",value = "日志对象",paramType = "body",dataType = "LogByPageVo"),
    })
    @PostMapping(value = "/getSelectLog")
    public Map getSelectLog(@RequestBody LogByPageVo log1) throws Exception {
//        int page = log1.getPage();
//        int size = log1.getSize();
//        String log_type = log1.getLog_type();
//        String start_log_time = log1.getStart_log_time();
//        String end_log_time = log1.getEnd_log_time();
        if (!(log1.getPage()>0 && log1.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        Date startdate = FormatTool.getDate(log1.getStart_log_time(), "yyyy-MM-dd HH:mm:ss");
        Date enddate = FormatTool.getDate(log1.getEnd_log_time(), "yyyy-MM-dd HH:mm:ss");
        List<LogVo> selectLog = logService.getSelectLog((log1.getPage() - 1) * log1.getSize(), log1.getSize(), log1.getLog_type(), startdate, enddate);
        Integer total = logService.selectLogCount(log1.getLog_type(),startdate,enddate);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(selectLog);
        jsonResult.set("total",total);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了Log日志");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "查询角色",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role",value = "角色对象",paramType = "body",dataType = "RoleByPageVo"),
    })
    @PostMapping(value = "/selectRole")
    public Map selectRole(@RequestBody RoleByPageVo role) throws Exception {
//        int page = role.getPage();
//        int size = role.getSize();
//        String role_name = role.getRole_name();
        if (!(role.getPage()>0 && role.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        List<Role> roles = adminService.selectRole((role.getPage()-1)*role.getSize(), role.getSize(), role.getRole_name());
        Integer total = adminService.selectRoleCount(role.getRole_name());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(roles);
        jsonResult.set("total",total);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了角色管理");
        logService.insertLog(log);
        return jsonResult.getMap();
    }


    @ApiOperation(value = "批量删除角色",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role",value = "角色对象",paramType = "body",dataType = "Role"),
    })
    @PostMapping(value = "/deleteRole")
    public Map deleteRole(@RequestBody List<Role> roles) throws Exception {
        for (int i =0;i<roles.size();i++){
            int j = adminService.deleteRole(roles.get(i).getRole_id());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了角色");
        logService.insertLog(log);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "单个删除角色",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "角色id",paramType = "query",dataType = "int"),
    })
    @PostMapping(value = "/deleteRoleOne")
    public Map deleteRoleOne(Integer id) throws Exception {
        int i = adminService.deleteRole(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了角色");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "修改角色",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleVo",value = "角色对象",paramType = "body",dataType = "RoleVo"),

    })
    @PostMapping(value = "/updateRole")
    public Map updateRole(@RequestBody RoleVo roleVo) throws Exception {

        Integer i = adminService.updateRole(roleVo.getRole_name(),roleVo.getRole_desc(),roleVo.getRole_id());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        jsonResult.setData(i);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("修改方法");
        log.setLog_content("修改了角色");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "所有菜单",produces = "query")
    @PostMapping(value = "/selectMenu")
    public Map selectMenu() throws Exception {

        List<Menu> menus = adminService.selectMenu();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(menus);

        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "role",value = "角色对象",paramType = "body",dataType = "RoleVo"),

    })
    @ApiOperation(value = "添加角色",produces = "query")
    @PostMapping(value = "/addRole")
    public Map addRole(@RequestBody RoleVo role) throws Exception {

        adminService.addRole(role);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");

        return jsonResult.getMap();
    }


    @ApiOperation(value = "查询操作员",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminRoleByPageVo",value = "操作员对象",paramType = "body",dataType = "AdminRoleByPageVo"),
    })
    @PostMapping(value = "/selectAdminRole")
    public Map selectAdminRole(@RequestBody AdminRoleByPageVo adminRoleByPageVo) throws Exception {
//        int page = adminRoleByPageVo.getPage();
//        int size = adminRoleByPageVo.getSize();
//        String manage = adminRoleByPageVo.getManage();
//        int role_id = adminRoleByPageVo.getRole_id();
        if (!(adminRoleByPageVo.getPage()>0 && adminRoleByPageVo.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        List<AdminRoleVo> roles = adminService.selectAdminRole((adminRoleByPageVo.getPage()-1)*adminRoleByPageVo.getSize(), adminRoleByPageVo.getSize(),adminRoleByPageVo.getManage(),adminRoleByPageVo.getRole_id());
        Integer total = adminService.selectAdminRoleCount(adminRoleByPageVo.getManage(),adminRoleByPageVo.getRole_id());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(roles);
        jsonResult.set("total",total);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了操作员");
        logService.insertLog(log);
        return jsonResult.getMap();
    }
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminRoleVo",value = "操作员对象",paramType = "body",dataType = "AdminRoleVo"),
    })
    @ApiOperation(value = "添加操作员",produces = "query")
    @PostMapping(value = "/addAdminRole")
    public Map addAdminRole(@RequestBody AdminRoleVo adminRoleVo) throws Exception {

        adminService.addAdminRole(adminRoleVo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");

        return jsonResult.getMap();
    }


    @ApiOperation(value = "批量删除操作员",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin",value = "操作员对象",paramType = "body",dataType = "Admin"),
    })
    @PostMapping(value = "/deleteAdminRole")
    public Map deleteAdminRole(@RequestBody List<Admin> admin) throws Exception {
        for (int i =0;i<admin.size();i++){
            int j = adminService.deleteAdminRole(admin.get(i).getAdmin_id());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了操作员");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "单个删除操作员",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "操作员id",paramType = "query",dataType = "int"),
    })
    @PostMapping(value = "/deleteAdminRoleOne")
    public Map deleteAdminRoleOne(Integer id) throws Exception {
        int j = adminService.deleteAdminRole(id);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了操作员");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "修改操作员",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin_phone",value = "操作员手机号",paramType = "query"),
            @ApiImplicitParam(name = "admin_name",value = "操作员名",paramType = "query"),
            @ApiImplicitParam(name = "role_id",value = "角色id",paramType = "query"),
            @ApiImplicitParam(name = "admin_id",value = "操作员id",paramType = "query"),
    })
    @PostMapping(value = "/updateAdminRole")
    public Map updateAdminRole(String admin_phone,String admin_name,Integer role_id,Integer admin_id) throws Exception {

        Integer i = adminService.updateAdminRole(admin_phone, admin_name, role_id, admin_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        jsonResult.setData(i);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("修改方法");
        log.setLog_content("修改了操作员");
        logService.insertLog(log);
        return jsonResult.getMap();
    }


    @ApiOperation(value = "重置密码",produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin",value = "操作员id",paramType = "body",dataType = "Admin"),
    })
    @PostMapping(value = "/updatePasswordAdmin")
    public Map updatePasswordAdmin(@RequestBody List<Admin> admin) throws Exception {
        for (int i = 0;i<admin.size();i++){
            int j = adminService.updatePasswordAdmin(admin.get(i).getAdmin_id());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("修改方法");
        log.setLog_content("重置了操作员密码");
        logService.insertLog(log);
        return jsonResult.getMap();
    }



    //////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////


    @ApiImplicitParams({
            @ApiImplicitParam(name = "userManagerByPageVo", value = "用户信息对象", paramType = "body", dataType = "UserManagerByPageVo"),
    })
    @PostMapping("/selectUserManagerByName")
    @ApiOperation(value = "用户管理接口", produces = "query")
    public Map selectAllByNameAndPhone(@RequestBody UserManagerByPageVo userManagerByPageVo) throws BusinessException {
//    ,Integer state,Integer site_id,String phone
        if (!(userManagerByPageVo.getPage() > 0 && userManagerByPageVo.getSize() > 0)) {
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        List<UserManagerVo> users = userManagerService.selectAllByNameAndPhone((userManagerByPageVo.getPage() - 1) * userManagerByPageVo.getSize(),
                userManagerByPageVo.getSize(),
                userManagerByPageVo.getName(), userManagerByPageVo.getState(), userManagerByPageVo.getSite_id());
        Integer total=userManagerService.selectUserManageCount(userManagerByPageVo.getName(),
                userManagerByPageVo.getState(),userManagerByPageVo.getSite_id());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(users);
        jsonResult.set("total",total);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了用户信息");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", paramType = "query", dataType = "int",required = true)
    })
    @PostMapping("/selectUserManagerById")
    @ApiOperation(value = "通过id查询用户基本信息", produces = "query")
    public Map selectUserManagerById(@RequestParam("id") Integer id) {
        List<UserManagerVo> userManagerVos = userManagerService.selectManagerById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(userManagerVos);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了用户基本信息");
        logService.insertLog(log);
        return jsonResult.getMap();
    }
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id",value = "用户编号",paramType = "query"),
//    })
//    @PostMapping("/updateUserState")
//    @ApiOperation(value = "冻结用户id",produces = "query")
//    public Map updateUserState(Integer id){
//        Integer integer = userManagerService.updateUserState(id);
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setCode("200");
//        jsonResult.setMsg("冻结成功");
//        jsonResult.setData(integer);
//        return jsonResult.getMap();
//    }
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id",value = "用户编号",paramType = "query"),
//    })
//    @PostMapping("/updateOutState")
//    @ApiOperation(value = "解冻用户id",produces = "query")
//    public Map updateOutState(Integer id){
//        Integer integer = userManagerService.updateOutSate(id);
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setCode("200");
//        jsonResult.setMsg("解冻成功");
//        jsonResult.setData(integer);
//        return jsonResult.getMap();
//    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "user", value = "用户对象", paramType = "body", dataType = "User"),
    })
    @PostMapping("/updateAllState")
    @ApiOperation(value = "批量冻结用户id", produces = "query")
    public Map updateAllState(@RequestBody List<User> user) {
        for (int i=0;i<user.size();i++){
            int j =userManagerService.updateALlState(user.get(i).getId());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("冻结成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("冻结方法");
        log.setLog_content("冻结了用户");
        logService.insertLog(log);
        return jsonResult.getMap();
    }



    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户编号", paramType = "query",dataType = "int"),
    })
    @PostMapping("/updateAllStateById")
    @ApiOperation(value = "冻结单个用户id", produces = "query")
    public Map updateAllStateById(Integer id) {

        int i = userManagerService.updateALlState(id);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("冻结成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("冻结方法");
        log.setLog_content("冻结了用户");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "users", value = "用户编号", paramType = "body", dataType = "User"),
    })
    @PostMapping("/updateOutAllState")
    @ApiOperation(value = "批量解冻用户id", produces = "query")
    public Map updateOutAllState(@RequestBody List<User> users) {
        for (int i = 0;i<users.size();i++){
            int j = userManagerService.updateOutALlState(users.get(i).getId());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("解冻成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("解冻方法");
        log.setLog_content("解冻了用户");
        logService.insertLog(log);
        return jsonResult.getMap();
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户编号", paramType = "query",dataType = "int"),
    })
    @PostMapping("/updateOutState")
    @ApiOperation(value = "单个解冻用户id", produces = "query")
    public Map updateOutState(Integer id) {
        int j = userManagerService.updateOutALlState(id);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("解冻成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("解冻方法");
        log.setLog_content("解冻了用户");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户编号",paramType = "query",dataType = "int",required = true),
    })
    @ApiOperation(value = "通过id查询用户收货地址",produces = "query")
    @PostMapping("/selectUserAddress")
    public Map selectUserAddress(@RequestParam("id") Integer id){
        List<Address> addresses = userManagerService.selectUserAddress(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(addresses);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了用户收货地址");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "userOrderDetailByPageVo",value = "用户编号",paramType = "body",dataType = "UserOrderDetailByPageVo",required = true),

    })
    @ApiOperation(value = "根据用户id查询订单详情",produces = "query")
    @PostMapping("/selectUserOrder")
    public Map selectUserOrder(@RequestBody UserOrderDetailByPageVo userOrderDetailByPageVo) throws BusinessException {
        if (!(userOrderDetailByPageVo.getPage()>0 && userOrderDetailByPageVo.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        List<UserOrderDetailVo> userOrderDetailVos = userManagerService.selectUserOrder((userOrderDetailByPageVo.getPage()-1)*userOrderDetailByPageVo.getSize(),userOrderDetailByPageVo.getSize(),userOrderDetailByPageVo.getId());
        Integer total = userManagerService.selectUserCount(userOrderDetailByPageVo.getId());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(userOrderDetailVos);
        jsonResult.set("total",total);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了用户订单详情");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "userOrderDetailSelectVo",value = "派送订单对象",paramType = "body",dataType = "UserOrderDetailSelectVo"),

    })
    @PostMapping("/selectUserByNameAndPhone")
    @ApiOperation(value = "查询派送订单详情",produces = "query")
    public Map selectUserByNameAndPhone(@RequestBody UserOrderDetailSelectVo userOrderDetailSelectVo) throws BusinessException {
//    ,Integer state,Integer site_id,String phone
        if (!(userOrderDetailSelectVo.getPage()>0 && userOrderDetailSelectVo.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }
        Date startdate = FormatTool.getDate(userOrderDetailSelectVo.getStartdispatch_time(), "yyyy-MM-dd HH:mm:ss");
        Date enddate = FormatTool.getDate(userOrderDetailSelectVo.getEnddispatch_time(), "yyyy-MM-dd HH:mm:ss");
        List<UserOrderDetailVo> userOrderDetailVos= userManagerService.selectUserByNameAndPhone((userOrderDetailSelectVo.getPage() - 1) * userOrderDetailSelectVo.getSize(), userOrderDetailSelectVo.getSize(),
                userOrderDetailSelectVo.getAll(),userOrderDetailSelectVo.getState(),userOrderDetailSelectVo.getSite_id(),startdate,enddate);
        Integer total =userManagerService.selectByNameCount(userOrderDetailSelectVo.getAll(),userOrderDetailSelectVo.getState(),userOrderDetailSelectVo.getSite_id(),startdate,enddate);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(userOrderDetailVos);
        jsonResult.set("total",total);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了用户订单详情");
        logService.insertLog(log);
        return jsonResult.getMap();
    }
//
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "order_id",value = "订单编号",paramType = "query"),
//    })
//    @PostMapping("/deleteUserManagerByOrderId")
//    @ApiOperation(value = "单个删除用户信息",produces = "query")
//    public Map deleteUserManagerByOrderId (String order_id){
//        int i = userManagerService.deleteUserManagerByOrderId(order_id);
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setCode("200");
//        jsonResult.setMsg("删除成功");
//        jsonResult.setData(i);
//        return jsonResult.getMap();
//
//    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "userOrderDetailVos",value = "订单对象",paramType = "body",dataType = "UserOrderDetailVo",required = false),
    })
    @PostMapping("/deleteUserManagerByOrderIdAll")
    @ApiOperation(value = "批量删除用户订单信息")
    public Map deleteUserManagerByOrderIdAll (@RequestBody List<UserOrderDetailVo> userOrderDetailVos){
        System.out.println("/////////////////"+userOrderDetailVos.size());
        for (int i = 0;i<userOrderDetailVos.size();i++){
            int j = userManagerService.deleteUser(userOrderDetailVos.get(i).getOrder_id());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了用户订单信息");
        logService.insertLog(log);
        return jsonResult.getMap();

    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "订单编号",paramType = "query",required = true),
    })
    @PostMapping(value = "/deleteUserManagerByOrderId")
    @ApiOperation(value = "删除单个用户订单信息",produces = "query")
    public Map deleteUserManagerByOrderId(String id){
        int i = userManagerService.deleteUser(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了用户订单信息");
        logService.insertLog(log);
        return jsonResult.getMap();

    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "order_id",value = "订单编号",paramType = "query",dataType = "string"),
    })
    @ApiOperation(value = "查询用户派送订单详情",produces = "query")
    @PostMapping("/selectUserOrderDetailAll")
    public Map selectUserOrderDetailAll(@RequestParam("order_id") String order_id){
        List<UserOrderDetailUpdateVo> userOrderDetailUpdateVos = userManagerService.selectUserOrderDetailAll(order_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(userOrderDetailUpdateVos);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了用户订单详情");
        logService.insertLog(log);
        return jsonResult.getMap();
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "materials",value = "物料对象",paramType = "body",dataType = "MaterialsByPageVo"),
    })
    @PostMapping("/selectMaterialsAll")
    @ApiOperation(value = "查询物料",produces = "query")
    public Map selectMaterialsAll(@RequestBody MaterialsByPageVo materials) throws BusinessException {
//        int page = materials.getPage();
//        int size = materials.getSize();
//        String materials_name = materials.getMaterials_name();
//        int site_id = materials.getSite_id();
        if (!(materials.getPage()>0 && materials.getSize()>0)){
            throw new BusinessException(ExceptionCode.WRONG_PAGE_SIZE);
        }

        List<MaterialsVo> materialsVos= userManagerService.selectMaterialsAll(( materials.getPage() - 1) * materials.getSize(),  materials.getSize(),materials.getMaterials_name(),materials.getSite_id());
        Integer total=userManagerService.selectMaterialsCount(materials.getMaterials_name(),materials.getSite_id());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(materialsVos);
        jsonResult.set("total",total);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("查询方法");
        log.setLog_content("查询了物料详情");
        logService.insertLog(log);
        return jsonResult.getMap();
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "materials",value = "物料对象",paramType = "body",required = false,dataType = "Materials"),

    })
    @PostMapping("/deleteMaterials")
    @ApiOperation(value = "批量删除物料",produces = "query")
    public Map deleteMaterials(@RequestBody List<Materials> materials) {
        for (int j=0;j<materials.size();j++){
            int i = userManagerService.deleteMaterials(materials.get(j).getMaterials_id());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了物料");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "materials_id",value = "物料id",paramType = "query",required = true),

    })
    @PostMapping("/deleteMaterialsOne")
    @ApiOperation(value = "单个删除物料",produces = "query")
    public Map deleteMaterialsOne(Integer materials_id) {
        int i = userManagerService.deleteMaterials(materials_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("删除方法");
        log.setLog_content("删除了物料");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    //    @ApiImplicitParams({
//            @ApiImplicitParam(name = "materials_name",value = "物料名字",paramType = "query"),
//            @ApiImplicitParam(name = "materials_num",value = "物料数量",paramType = "query"),
//            @ApiImplicitParam(name = "materials_unit",value = "物料单位",paramType = "query"),
//            @ApiImplicitParam(name = "materials_cost",value = "物料成本单价",paramType = "query"),
//            @ApiImplicitParam(name = "materials_price",value = "物料售价",paramType = "query"),
//            @ApiImplicitParam(name = "site_id",value = "归属站点",paramType = "query"),
//
//    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materials",value = "物料对象",paramType = "body",dataType = "Materials"),
    })
    @PostMapping("/insertMaterials")
    @ApiOperation(value = "添加物料",produces = "query")
    public Map insertMaterials(@RequestBody Materials materials) {
        userManagerService.insertMaterials(materials);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        jsonResult.setData(materials);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("添加方法");
        log.setLog_content("添加了物料");
        logService.insertLog(log);
        return jsonResult.getMap();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "materials",value = "物料对象",paramType = "body",dataType = "Materials"),

    })
    @PostMapping("/updateMaterials")
    @ApiOperation(value = "修改物料",produces = "query")
    public Map updateMaterials(@RequestBody Materials materials) {
        userManagerService.updateMaterials(materials);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改完成");
        jsonResult.setData(materials);
        Log log = new Log();
        log.setLog_admin_id(1);
        log.setLog_type("修改方法");
        log.setLog_content("修改了物料");
        logService.insertLog(log);
        return jsonResult.getMap();
    }



    @ApiImplicitParams({
            @ApiImplicitParam(name = "materials_id",value = "物料id",paramType = "query",dataType = "int",required = true),

    })
    @PostMapping("/editMaterials")
    @ApiOperation(value = "通过ID查询物料",produces = "query")
    public Map editMaterials(@RequestParam("materials_id") Integer materials_id) {
        List<MaterialsVo> materialsVos = userManagerService.editMaterials(materials_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(materialsVos);
        return jsonResult.getMap();
    }



    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin_id",value = "管理员id",paramType = "query",dataType = "int",required = true),

    })
    @PostMapping("/editAdminRoleVo")
    @ApiOperation(value = "通过ID查询操作员",produces = "query")
    public Map editAdminRoleVo(@RequestParam("admin_id") Integer admin_id) {
        List<AdminRoleVo> adminRoleVos = userManagerService.editAdminRoleVo(admin_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(adminRoleVos);
        return jsonResult.getMap();
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id",value = "角色id",paramType = "query",dataType = "int",required = true),

    })
    @PostMapping("/editRoleVo")
    @ApiOperation(value = "通过ID查询角色",produces = "query")
    public Map editRoleVo(@RequestParam("role_id") Integer role_id) {
        List<RoleVo> roleVos = userManagerService.editRoleVo(role_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(roleVos);
        return jsonResult.getMap();
    }


}
